<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子34-JS进阶（二）</title>
    </head>

    <body>
        <pre>
            <code>
                    // 例子34

                    var person = {
                        name: 'Tom',
                        age: 20
                    }

                    // 使用for-in枚举person的属性
                    var params = [];

                    for(var key in person) {
                        params.push(key);
                    }

                    // 查看枚举结果
                    console.log(params);  // ['name', 'age']

                    // 重新设置name属性的类型，让其不可被枚举
                    Object.defineProperty(person, 'name', {
                        enumerable: false
                    })

                    var params_ = [];
                    for(var key in person) {
                        params_.push(key)
                    }

                    // 再次查看枚举结果
                    console.log(params_); // ['age']
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/34.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>

</html>